package com.wayne.leetcode.problems;

import java.util.Arrays;
import java.util.Comparator;

public class Solution1029 {
  public static int twoCitySchedCost(int[][] costs) {
    Arrays.sort(costs, (o1, o2) -> o1[0] - o1[1] - (o2[0] - o2[1]));
    int n = costs.length / 2;
    int total =0 ;
    for (int i=0;i<n;i++) {
      total += costs[i][0];
      total += costs[i+n][1];
    }
    return total;
  }

  public static void main(String[] args) {
    twoCitySchedCost(new int[][]{{259, 77}, {448, 54}, {926, 667}, {184, 139}, {840, 118}, {577, 469}});
  }
}